<?php include("src/sendEmail_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Send Email :: First United Services LLC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>
<link rel="stylesheet" href="js/fancybox/fancy.css" type="text/css" media="screen">
<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.0.0.js"></script>
<script language="javascript" type="text/javascript">

	
	
	function showMessage(show_msg){
		switch(show_msg){
			case '1'://error
				coolMessage('error',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case '2'://alert
				coolMessage('alert',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case '3'://information
				coolMessage('information',"<?php echo $_SESSION["msg_cool"];?>", function (){ window.location.href = '/listEmail.php'});
			break;
			
			default:
				
			break;
		}
		return false;
	}
	
	var cont = 0;
	var maximum = 5;
	function most(){
		if (cont < maximum ){
			cont++;		
			$("#div_file").append("<div id='file_"+cont+"'><input type='file' name='file[]'/></div>");
		}
		
		if(cont >0)
			document.getElementById('divDelet').disabled = 0;
	}
	
	function less(){
		if(cont > 0 ){
			$("#file_"+cont).remove();
			cont--;
		}
		
		if(cont == 0)
			document.getElementById('divDelet').disabled = 1;
	}
	
	function isMail(valor) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
			return (true);
		else
			return (false);
	}
	
	function validate(){
		var email_subject = document.getElementById('email_subject').value;
		var email_to = document.getElementById('email_to').value;
		
		var msg = ''
		
		if ( email_subject == '' )
			msg+='- Please type a subject in the Subject box.<br />';
		
		if ( email_to == '' )
			msg+='- Please type an email who you send to.<br />';
		else{
			if ( ! isMail (email_to) )
				msg += '- Wrong email.<br />';
		}
		
		if(msg==''){
			document.getElementById('btn').disabled="disabled";
			document.getElementById('btn').value="sending...";
			document.getElementById('form').submit();
			coolMessage('loadingInfo','cargardo...');
			return true;
		}
		else{
			coolMessage('error', msg);
			return false
		}		
	}
</script>
</head>
<body onload="showMessage('<?php echo $show_msg;?>')">
<?php $item_select = 7; include("menu.php");?><br />
    <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="add" id="add" value="1"/>
    <div class="content_grv">
        <table width="90%" align="center" class="shadow">
            <tr>
                <td class="title">E-mail</td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">                                                
                        <tr>
                            <td align="right" width="20%"><span class="lbl_gray">From:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td><span class="lbl_black"><?php  echo $_SESSION['use_email'];?></span></td>                            
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">To:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="email_to" id="email_to" class="text_grv" value="<?php echo $email_to?>" size="90"/></td>                            
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Subject:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="email_subject" id="email_subject" class="text_grv" value="" size="90"/></td>                            
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Attachment:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            <input type="file" name="file[]" />
                            <input type="button" value="+" onClick="javascript: most();" class="button_grv"/>&nbsp;
                            <input type="button" value="-" id="divDelet" onClick="javascript: less()" class="button_grv_cancel" disabled="disabled"/>
                            </td>                            
                        </tr> 
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>
                            	<div id="div_file">
									
								</div>
                            </td>                            
                        </tr>
                        <tr>
                        	<td colspan="3" align="center"><?php echo @$fckeditor->Create();?></td>
						</tr>
                        <tr><td colspan="3" align="center">&nbsp;</td></tr>
                        <tr>
                            <td colspan="3" align="center">
                                <input type="button" class="button_grv" value="Send" id="btn" onclick="javascript: return validate();" />                                
                                <input type="reset" value="Reset" class="button_grv_cancel"/>
                                <input type="button" class="button_grv_cancel" value="Cancel" onClick="javascript: window.location.href='listEmail.php';" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>